<template>
     <div class="bottle-container">
        <div class="bottle">
            
            <div class="bottle-body">
                <div class="liquid" ref="liquid">
                    <div class="bubble"></div>
                    <div class="bubble"></div>
                    <div class="bubble"></div>
                    <div class="bubble"></div>
                    <div class="bubble"></div>
                </div>
            </div>
        </div>
        <div class="bottle-shadow"></div>
    </div>
</template>
<script>
// 辅助函数：调整颜色亮度
function adjustColor(hex, percent) {
    let R = parseInt(hex.substring(1,3),16);
    let G = parseInt(hex.substring(3,5),16);
    let B = parseInt(hex.substring(5,7),16);
    
    R = Math.min(255, Math.max(0, R + R * percent / 100));
    G = Math.min(255, Math.max(0, G + G * percent / 100));
    B = Math.min(255, Math.max(0, B + B * percent / 100));
    
    R = Math.round(R).toString(16).padStart(2, '0');
    G = Math.round(G).toString(16).padStart(2, '0');
    B = Math.round(B).toString(16).padStart(2, '0');
    
    return `#${R}${G}${B}`;
}

export default {
    name: 'Bollte',
    props:{
        color:{
            type:String
        },
        height: {
            type: Number
        }
    },
    data(){
      return {
        
      }
    },
    mounted(){
        
        let liquid = this.$refs.liquid;

        let color = this.color || '#' + Math.floor(Math.random()*16777215).toString(16);
        let height = this.height || Math.floor(Math.random() * 60) + 20;

        liquid.style.background = `linear-gradient(to top, ${adjustColor(color, -30)}, ${color}`;
        liquid.style.height = `${height}%`;
        

    },
    beforeDestroy(){
        
    },
    watch: {
        color:{
            handler(val){
                console.log(val)
                let liquid = this.$refs.liquid;
                liquid.style.background = `linear-gradient(to top, ${adjustColor(val, -30)}, ${val}`;
            },
            deep: true
        },
        height(val){
            let liquid = this.$refs.liquid;
            liquid.style.height = `${val}%`;
        }
    },
    computed:{
       
        
    },
    methods:{
        
    }
   
  }
  </script>
  
  <style scoped>
   
   .bottle-container {
        width: 150px;
        position: relative;
        perspective: 1000px;
    }

    .bottle {
        position: relative;
        height: 210px;
        width: 80px;
        margin: 0 auto;
        transform-style: preserve-3d;
        transform: rotateX(10deg);
    }

    .bottle::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 30px;
        height: 10px;
        background: linear-gradient(to right, #c9c9c9, #f5f5f5, #c9c9c9);
        border-radius: 5px 5px 0 0;
        z-index: 20;
    }

    .bottle::after {
        content: '';
        position: absolute;
        top: 10px;
        left: 50%;
        transform: translateX(-50%);
        width: 20px;
        height: 40px;
        background: linear-gradient(to right, #e6e6e6, #f9f9f9, #e6e6e6);
        border-radius: 0 0 5px 5px;
        z-index: 19;
    }

    .bottle-body {
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 65px;
        height: 170px;
        background: rgba(255, 255, 255, 0.1);
        border: 4px solid rgba(255, 255, 255, 0.4);
        border-top: none;
        border-bottom: 8px solid rgba(255, 255, 255, 0.5);
        border-radius: 0 0 40px 40px;
        overflow: hidden;
        z-index: 10;
        box-shadow: 
            0 10px 25px rgba(0, 0, 0, 0.3),
            inset 0 -7px 15px rgba(0, 0, 0, 0.2),
            inset 0 7px 10px rgba(255, 255, 255, 0.2);
    }

    .liquid {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 70%;
        background: linear-gradient(to top, #4a00e0, #8e2de2);
        border-radius: 0 0 16px 16px;
        transition: all 0.8s cubic-bezier(0.68, -0.55, 0.27, 1.55);
        z-index: 5;
    }

    .liquid::before {
        content: '';
        position: absolute;
        top: -5px;
        left: 0;
        width: 100%;
        height: 10px;
        background: inherit;
        border-radius: 50%;
        filter: blur(5px);
        opacity: 0.7;
    }

    .bubble {
        position: absolute;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 50%;
        animation: float 4s infinite ease-in-out;
        z-index: 6;
    }

    .bubble:nth-child(1) {
        width: 6px;
        height: 6px;
        top: 30%;
        left: 20%;
        animation-delay: 0.2s;
    }

    .bubble:nth-child(2) {
        width: 4px;
        height: 4px;
        top: 45%;
        left: 65%;
        animation-delay: 1.1s;
    }

    .bubble:nth-child(3) {
        width: 8px;
        height: 8px;
        top: 60%;
        left: 40%;
        animation-delay: 2.3s;
    }

    .bubble:nth-child(4) {
        width: 3px;
        height: 3px;
        top: 25%;
        left: 50%;
        animation-delay: 3.5s;
    }

    .bubble:nth-child(5) {
        width: 5px;
        height: 5px;
        top: 55%;
        left: 15%;
        animation-delay: 0.7s;
    }




    

    @keyframes float {
        0%, 100% {
            transform: translateY(0) translateX(0);
        }
        25% {
            transform: translateY(-20px) translateX(5px);
        }
        50% {
            transform: translateY(-40px) translateX(-5px);
        }
        75% {
            transform: translateY(-60px) translateX(3px);
        }
    }

    .bottle-shadow {
        width: 90px;
        height: 15px;
        background: rgba(0, 0, 0, 0.3);
        border-radius: 50%;
        margin: 15px auto 0;
        filter: blur(5px);
    }
    
    
    

    
  </style>
  